package com.sky.mapper;

import cn.mybatis.mp.core.mybatis.mapper.MybatisMapper;
import com.sky.entity.Bookcategories;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.Map;
import java.util.List;

/**
* @author 31827
* @description 针对表【bookcategories(图书分类关联表)】的数据库操作Mapper
* @createDate 2024-11-30 11:56:30
* @Entity com.sky.entity.Bookcategories
*/
@Mapper
public interface BookcategoriesMapper extends MybatisMapper<Bookcategories> {
    
    /**
     * 获取所有图书分类的统计数据
     * @return 分类统计数据列表
     */
    @Select("SELECT c.category_name as categoryName, COUNT(bk.book_id) as count " +
            "FROM categories c " +
            "LEFT JOIN bookcategories bk ON c.category_id = bk.category_id " +
            "GROUP BY c.category_id, c.category_name " +
            "ORDER BY count DESC")
    List<Map<String, Object>> selectCategoryStats();
}
